import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * 
 */

/**
 * @author engebretsonm
 *
 */
public class DateTest {

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testBA1() {
		
		boolean caughtException = false;
		try {
			new DateCalculator("", "");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testBA2() {
		boolean caughtException = false;
		try {
			new DateCalculator("1/1/1799", "1/1/1801");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testBA3() {
		
		try {
			Date date2 = new Date("3/1/2012");
			Date date1 = new Date("2/28/2012");
			try {
				assertTrue(date1.calculateNumberOfDaysBetween(date2) == 2);
			} catch (CalculationError e) {
				e.printStackTrace();
				fail("CalculationError");
			}
		} catch (InvalidDateString e) {
			fail("InvalidDateString");
		}
	}
	
	@Test
	public void testRLW1() {
		
		try {
			Date date1 = new Date("1/1/1800");
			Date date2 = new Date("1/1/2100");
			try {
				assertTrue(date1.calculateNumberOfDaysBetween(date2) == 109573);
			} catch (CalculationError e) {
				e.printStackTrace();
				fail("CalculationError");
			}
		} catch (InvalidDateString e) {
			fail("InvalidDateString");
		}
	}
	
	@Test
	public void testRLW2() {
		
		boolean caughtException = false;
		try {
			new DateCalculator("12/31/1799", "1/1/2100");
		} catch (InvalidDateString e) {
			caughtException = true;
		} catch (CalculationError e) {

		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testRLW3() {
		try {
			Date date2 = new Date("1/1/1800");
			Date date1 = new Date("1/1/2100");
			date1.calculateNumberOfDaysBetween(date2);
			fail("Should throw an exception");
		} catch (InvalidDateString | CalculationError e) {
			assertTrue(true);
		}
	}
	
	@Test
	public void testCS1() {
		boolean caughtException = false;
		try {
			new DateCalculator("02-29-1900", "03-01-1900");
		} catch (InvalidDateString e) {
			caughtException = true;
		} catch (CalculationError e) {
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testCS2() {
		try {
			Date date1 = new Date("2/29/2000");
			Date date2 = new Date("3/1/2000");
			try {
				assertTrue(date1.calculateNumberOfDaysBetween(date2) == 1);
			} catch (CalculationError e) {
				e.printStackTrace();
				fail("CalculationError");
			}
		} catch (InvalidDateString e) {
			fail("InvalidDateString");
		}
	}
	
	@Test
	public void testCS3() {
		boolean caughtException = false;
		try {
			new DateCalculator("13-01-2000", "08-05-2005");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testCS4() {
		boolean caughtException = false;
		try {
			new DateCalculator("08/15/2101", "08-01-1900");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testHE1() {
		try {
			Date date1 = new Date("3/15/2004");
			Date date2 = new Date("4/16/2005");
			try {
				assertTrue(date1.calculateNumberOfDaysBetween(date2) == 397);
			} catch (CalculationError e) {
				e.printStackTrace();
				fail("CalculationError");
			}
		} catch (InvalidDateString e) {
			fail("InvalidDateString");
		}
	}
	
	@Test
	public void testHE2() {
		try {
			Date date1 = new Date("3/15/2004");
			Date date2 = new Date("4/18/2004");
			try {
				assertTrue(date1.calculateNumberOfDaysBetween(date2) == 34);
			} catch (CalculationError e) {
				e.printStackTrace();
				fail("CalculationError");
			}
		} catch (InvalidDateString e) {
			fail("InvalidDateString");
		}
	}
	
	@Test
	public void testHE3() {
		boolean caughtException = false;
		try {
			new DateCalculator("2/29/1900", "03/18/2005");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testHE4() {
		try {
			Date date1 = new Date("12/12/2012");
			Date date2 = new Date("12/12/2012");
			try {
				assertTrue(date1.calculateNumberOfDaysBetween(date2) == 0);
			} catch (CalculationError e) {
				e.printStackTrace();
				fail("CalculationError");
			}
		} catch (InvalidDateString e) {
			fail("InvalidDateString");
		}
	}
	
	@Test
	public void testHE5() {
		boolean caughtException = false;
		try {
			new DateCalculator("2/1/2003", "3/1\2003");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testHE6() {
		boolean caughtException = false;
		try {
			new DateCalculator("12/12/2012", "");
		} catch (InvalidDateString e) {
			//e.printStackTrace();
			caughtException = true;
		} catch (CalculationError e) {
			//e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testHE7() {
		boolean caughtException = false;
		try {
			String[] args = {"3/1/2014", "3/2/2014", "3/3/20014"};
			new DateCalculator(args);
		} catch (InvalidDateString e) {
			caughtException = true;
		} catch (CalculationError e) {
			e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}
	
	@Test
	public void testHE8() {
		boolean caughtException = false;
		try {
			String[] args = {"0/1/2014", "1/1/2014"};
			new DateCalculator(args);
		} catch (InvalidDateString e) {
			caughtException = true;
		} catch (CalculationError e) {
			e.printStackTrace();
			//caughtException = true;
		}
		assertTrue(caughtException);
	}

}
